#Execute this script to configure and push the project automatically
#based on values defined in `settings.json`

#!/bin/bash

function quit {
    echo $1
    ./utils/cleanit.sh
    exit 127
}

if [ ! -f settings.json ] && [ ! $# == 1 ]; then
  echo "Define a settings.json file, start from settings.json.example"
  echo "or pass an argument specifying the lcoation of the settings file:"
  echo "Ex: ./doit.sh mysettings.json" 
  exit 1
fi

./utils/configure.py $1 && bash ./utils/setpermissions.sh && ./sync.sh || quit "There was an error in deployment.  Quitting and cleaning up..."

pushd cgi-bin && php initalize_database.php && popd || quit "There was an error in initializing the database.  Quitting and cleaning up..."

./utils/cleanit.sh || quit "There was an error in cleaning up.  Check everything to make sure its okay..."

echo "All done with InSEAM deployment!" 